$("#S_date").datetimepicker(
        {
            language: "zh-CN",
            todayBtn: 1,
            autoclose: 1,
            todayHighlight: 1,
            startView: 3,
            minView: 3,
            startDate:"-3m",
            endDate:"+0m",
            forceParse: true,
            format: "yyyy-mm"
        });

        $(document).ready(function () {
                setTimeout(function () {
                    $("#diff_search").val(1);
                    getLoad(1);
                }, 10);
            });



function getLoad(page) {
    var stime = $("#S_date").val();
    var search_type = $("#diff_search").val();

    $.ajax({
        url: "/app/member/agent/getReport",
        dataType: "json",
        async: true,
        data: {"t": Math.random(),
            "S_date": stime,
            "Type": search_type
        },
        type: "post",
        beforeSend: function () {
            layer.load(2, {shadeClose: true, shade: 0.2});
        },
        success: function (data) {
            if (data.status <= 0) {
                layer.alert(data.info);
                return false;
            } else {
                var info = data.list;
                if (search_type == 1) {
                    layer.closeAll('loading');
                    var m = info.total;
                    var s = info.sum;
                    if (!IsNull(m)) {
                        for (var key in m) {
                            for(var i in m[key]){
                                var svalue = m[key][i];
                                $("#info ." + key+" ."+i).html(svalue);
                            }
                        }
                    }
                    if (!IsNull(s)) {
                        for (var i in s) {
                            $("#sum ." + i).html(s[i]);
                        }
                    }
                } else if (search_type == 2) {
                    var details = data.list.m;
                    if (!IsNull(details)) {
                        var shtml = "";
                        var ii= 0;
                        for (var key in details) {
                            var ivalues = details[key];
                            var _cla = 'style="background-color: #eff;"';

                            shtml += '<tr '+_cla+'>';
                            shtml += '<td rowspan="2">' + key + '</td>';
                            shtml += '<td>流水</td>';
                            shtml += '<td >' + chrval(ivalues.tyls) + '</td>';
                            shtml += '<td >' + chrval(ivalues.cpls) + '</td>';
                            shtml += '<td >' + chrval(ivalues.bbls) + '</td>';
                            shtml += '<td >' + chrval(ivalues.mgls) +'</td>';
                            shtml += '<td >' + chrval(ivalues.vipls) + '</td>';
                            shtml += '<td >' + chrval(ivalues.gdls) +'</td>';
                            shtml += '<td >' + chrval(ivalues.agls) +'</td>';
                            shtml += '<td >' + chrval(ivalues.ogls)+'</td>';
                            shtml += '<td >' + chrval(ivalues.obls) +'</td>';
                            shtml += '<td >' + chrval(ivalues.bglls) +'</td>';
                            shtml += '<td >' + chrval(ivalues.dglls) +'</td>';
                            shtml += '<td >' + chrval(ivalues.vrlls) +'</td>';

                            shtml += '<td >' + chrval(ivalues.bbls_w) + '</td>';
                            shtml += '<td >' + chrval(ivalues.mgls_w) +'</td>';
                            shtml += '<td >' + chrval(ivalues.vipls_w) + '</td>';
                            shtml += '<td >' + chrval(ivalues.gdls_w)+'</td>';
                            shtml += '<td >' + chrval(ivalues.hbls_w)+ '</td>';
                            shtml += '<td >' + chrval(ivalues.byuls_w) +'</td>';

                            shtml += '<td >' + chrval(ivalues.aptls_w)+'</td>';
                            shtml += '<td >' + chrval(ivalues.endols_w)+ '</td>';
                            shtml += '<td >' + chrval(ivalues.ynxls_w) +'</td>';
                            shtml += '<td >' + chrval(ivalues.bgls_w) +'</td>';
                            shtml += '<td >' + chrval(ivalues.ttgls_w) + '</td>';
                            shtml += '<td >' + chrval(ivalues.sgls_w) +'</td>';
                            shtml += '<td >' + chrval(ivalues.pgls_w) +'</td>';
                            shtml += '<td >' + chrval(ivalues.mwls_w) + '</td>';

                            shtml += '<td rowspan="2">' + chrval(ivalues.ckzj) + '</td>';
                            shtml += '<td rowspan="2">' + chrval(ivalues.hkzj) + '</td>';
                            shtml += '<td rowspan="2">' + chrval(ivalues.tkzj) + '</td>';
                            shtml += '<td rowspan="2">' + chrval(ivalues.fszj) + '</td>';
                            shtml += '<td rowspan="2">' + chrval(ivalues.hlzj) + '</td>';
                            shtml += '<td rowspan="2">' + chrval(ivalues.syzj) + '</td>';
                            shtml += '</tr>';

                            //-- 输赢
                            shtml += '<tr>';
                            shtml += '<td>输赢</td>';
                            shtml += '<td >' +chrval(ivalues.tysy) + '</td>';
                            shtml += '<td >' +chrval(ivalues.cpsy) + '</td>';
                            shtml += '<td >' +chrval(ivalues.bbsy) + '</td>';
                            shtml += '<td >' +chrval(ivalues.mgsy) +'</td>';
                            shtml += '<td >' +chrval(ivalues.vipsy) + '</td>';
                            shtml += '<td >' +chrval(ivalues.gdsy) +'</td>';
                            shtml += '<td >' +chrval(ivalues.agsy) +'</td>';
                            shtml += '<td >' +chrval(ivalues.ogsy) +'</td>';
                            shtml += '<td >' +chrval(ivalues.obsy) +'</td>';
                            shtml += '<td >' +chrval(ivalues.bglsy) +'</td>';
                            shtml += '<td >' +chrval(ivalues.dglsy) +'</td>';
                            shtml += '<td >' +chrval(ivalues.vrlsy) +'</td>';

                            shtml += '<td >' +chrval(ivalues.bbsy_w) + '</td>';
                            shtml += '<td >' +chrval(ivalues.mgsy_w) +'</td>';
                            shtml += '<td >' +chrval(ivalues.vipsy_w) + '</td>';
                            shtml += '<td >' +chrval(ivalues.gdsy_w) +'</td>';
                            shtml += '<td >' +chrval(ivalues.hbsy_w) + '</td>';
                            shtml += '<td >' +chrval(ivalues.byusy_w) +'</td>';

                            shtml += '<td >' +chrval(ivalues.aptsy_w) +'</td>';
                            shtml += '<td >' +chrval(ivalues.endosy_w) + '</td>';
                            shtml += '<td >' +chrval(ivalues.ynxsy_w) +'</td>';
                            shtml += '<td >' +chrval(ivalues.bgsy_w) +'</td>';
                            shtml += '<td >' +chrval(ivalues.ttgsy_w) + '</td>';
                            shtml += '<td >' +chrval(ivalues.sgsy_w) +'</td>';
                            shtml += '<td >' +chrval(ivalues.pgsy_w) +'</td>';
                            shtml += '<td >' +chrval(ivalues.mwsy_w) + '</td>';
                            shtml += '</tr>';

                            ii++;
                        }
                        $("#b_info").html(shtml);

//                    if (!IsNull(e)) {
//                        for (var i in s) {
//                            $("#m ." + i).html(getTwoFloor(s[i]));
//                        }
//                        $("#m .num").html(s.num + "人");
//                    }
                        var page = data.list.page;
                        if (!IsNull(page))
                            $("#page").html(page);

                    }else{
                        $("#b_info").html('<tr><td colspan="36" align="center">暂无数据</td></tr>');
                        $("#m").hide();
                    }
                }
                if (!IsNull(data.list.s.S_date))
                    $("#S_date").val(data.list.s.S_date);
                if (!IsNull(data.list.s.E_date))
                    $("#E_date").val(data.list.s.E_date);
            }
        },
        complete: function () {
            layer.closeAll('loading');
        },
        error: function () {
            layer.closeAll('loading');
            layer.alert("加载失败,请稍后在试...");
            return false;
        }
    });

}

function chrval(v){
    var str = 0.00;
    if(v==null)
        return str;
    if(parseInt(v)<0)
        return "<font style='color:red;'>"+v+"</font>";
    else
        return "<font style='color:blue;'>"+v+"</font>";
}


function searchDetail() {
    $("._a").hide();
    $("._b").show();
    $("#diff_search").val(2);

    getLoad(1);
}

function searchSum() {
    $("._b").hide();
    $("._a").show();
    $("#diff_search").val(1);
    getLoad(1);
}